// *************************************************************************************************
//
// MK3D Engine
// --------------------------------------
// Copyright (C) 2007-2011 Zeb (mailto: zebbey@gmail.com)
//
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//
// *************************************************************************************************

#ifndef __H_MK_MATH__
#define __H_MK_MATH__

#include "mk_aabb.h"

namespace MK3DE
{
	extern "C" MK3DE_API BOOL IsPointInRect(D3DXVECTOR2* leftTop, D3DXVECTOR2* rightButtom, D3DXVECTOR2* point);
	extern "C" MK3DE_API BOOL IsPointNearSegment(D3DXVECTOR2& p1, D3DXVECTOR2& p2, float x, float y, float rangeSq);
	extern "C" MK3DE_API BOOL AABBCollisionWithRay(/* out */ D3DXVECTOR3& pos, AABB& aabb, float x0, float y0, float z0, D3DXVECTOR3& dir);
	extern "C" MK3DE_API BOOL RayIntersectTriangle(D3DXVECTOR3& pos, D3DXVECTOR3& orig, D3DXVECTOR3& dir, D3DXVECTOR3& v0, D3DXVECTOR3& v1, D3DXVECTOR3& v2);
	extern "C" MK3DE_API void PlaneIntersectLine(/* out */ D3DXVECTOR3* pOut, D3DXPLANE* pP, D3DXVECTOR3* pV1, D3DXVECTOR3* pV2);
	extern "C" MK3DE_API void TransformAABB(/* out */ AABB* outAABB, AABB* inAABB, D3DXMATRIX* mat);
	extern "C" MK3DE_API int RandomInt(int nMin, int nMax);
	extern "C" MK3DE_API float RandomFloat(float fMin, float fMax);  
	extern "C" MK3DE_API void ProjectPoint(D3DXVECTOR3& outPos, D3DXVECTOR3& point, DWORD width, DWORD height, D3DXMATRIX& matView, D3DXMATRIX& matProj);
	extern "C" MK3DE_API float GaussianDistribution1(float x, float rho);
	extern "C" MK3DE_API float GaussianDistribution2(float x, float y, float rho);
	extern "C" MK3DE_API void QuaternionFromYawPitchRoll(D3DXQUATERNION& q, float yaw, float pitch, float roll);
	extern "C" MK3DE_API void QuaternionMultiply(D3DXQUATERNION& r, D3DXQUATERNION& q1, D3DXQUATERNION& q2);
	extern "C" MK3DE_API BOOL TestPlanePoints(D3DXPLANE& plane, D3DXVECTOR3* pts, DWORD count);
};

#endif // __H_MK_MATH__